﻿package  Classes{
	
	public class RC4Struct {
		var s:Array=new Array();
		var x:int;
		var y:int;
		public function RC4Struct() {
			InitZero();
		}
		
		public function InitZero():void 
		{
			var i:int;
			var j:int;
			var uc:int;
			for(i=0;i<256;i++) {
				s[i] = i;
			}
			for(i=0;i<256;i++) {
				j = (j+s[i])&255;
				uc = s[i];
				s[i] = s[j];
				s[j] = uc;
			}
		}
		
		public function NextByte():int 
		{
			var uc:int;
			x = (x+1)&255;
			y = (y+s[x])&255;
			uc = s[x];
			s[x] = s[y];
			s[y] = uc;
			return s[(s[x]+s[y])&255];
		}
		
		public function NextLong():int
		{
			var uc0:int = NextByte();
			var uc1:int = NextByte();
			var uc2:int = NextByte();
			var uc3:int = NextByte();
			return uc0+(uc1<<8)+(uc2<<16)+(uc3<<24);
		}
	}
	
}
